package com.example.dangerouscargodriver.ui.fragment.mine;

import android.content.Intent;
import android.graphics.Color;
import android.net.Uri;
import android.os.Bundle;

import androidx.annotation.Nullable;

import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.baiju.netmanager.Http.IHttpRequest;
import com.bumptech.glide.Glide;
import com.example.dangerouscargodriver.config.UserActionRecord;
import com.example.dangerouscargodriver.controller.AuthController;
import com.example.dangerouscargodriver.controller.EnterPlatformInfoController;
import com.example.dangerouscargodriver.controller.IControllerEventListener;
import com.example.dangerouscargodriver.controller.UserInfoController;
import com.example.dangerouscargodriver.entry.NumSign;
import com.example.dangerouscargodriver.entry.UserInfo;
import com.example.dangerouscargodriver.event.Event;
import com.example.dangerouscargodriver.event.LoadHttpResourceStatus;
import com.example.dangerouscargodriver.module.ResponseInfo;
import com.example.dangerouscargodriver.param.RemoteAPI;
import com.example.dangerouscargodriver.param.RemoteAPICmd;
import com.example.dangerouscargodriver.ui.activity.AccumulatePointsActivity;
import com.example.dangerouscargodriver.ui.activity.CompanyLineListActivity;
import com.example.dangerouscargodriver.ui.activity.MyOrderManagerActivity;
import com.example.dangerouscargodriver.ui.activity.PersonalLineListActivity;
import com.example.dangerouscargodriver.ui.activity.PersonalTruckDetailInfoActivity;
import com.example.dangerouscargodriver.ui.activity.CompanyTruckListActivity;
import com.example.dangerouscargodriver.ui.activity.CompanyListActivity;
import com.example.dangerouscargodriver.ui.activity.EmployeeManagerActivity;
import com.example.dangerouscargodriver.ui.activity.EnterGroupActivity;
import com.example.dangerouscargodriver.ui.activity.EnterPlatformCompanyStepOneActivity;
import com.example.dangerouscargodriver.ui.activity.EnterPlatformPersonalStepOneActivity;
import com.example.dangerouscargodriver.ui.activity.FollowOfficialAccountActivity;
import com.example.dangerouscargodriver.ui.activity.LogInActivity;
import com.example.dangerouscargodriver.ui.activity.MyResourceManagerActivity;
import com.example.dangerouscargodriver.ui.activity.SetupActivity;
import com.example.dangerouscargodriver.ui.activity.UserGuideActivity;
import com.example.dangerouscargodriver.ui.activity.UserWalletActivity;
import com.example.dangerouscargodriver.ui.fragment.AuthCheckFragment;
import com.example.dangerouscargodriver.ui.fragment.HttpRequestFragment;
import com.example.dangerouscargodriver.utils.DialogUtils;
import com.example.dangerouscargodriver.R;
import com.google.gson.Gson;

import org.json.JSONException;
import org.json.JSONObject;

import java.lang.ref.WeakReference;
import java.util.HashMap;

import de.hdodenhof.circleimageview.CircleImageView;
import q.rorbin.badgeview.QBadgeView;

public class MineFragment extends AuthCheckFragment implements View.OnClickListener{

    private static final String TAG = "MineFragment";
    private static final int HANDLER_LOAD_USER_ATTR_DONE = 1;
    private static final int HANDLER_GET_NUM_SIGN = 2;

    private static final String SERVICE_PHONE = "0571-88666547";
    public static final int ACTION_LOGIN = 1;
    public static final int ACTION_SETUP = 2;

    private View mRootView = null;
    private LinearLayout mWallet = null;
    private LinearLayout mEnterPlatform = null;
    private LinearLayout mEmployeeManager = null;
    private TextView mResource = null;

    private LinearLayout mDailService = null;
    private LinearLayout mSetup = null;
    private LinearLayout mEnterGroup = null;
    private LinearLayout mFollowOfficialAccount = null;
    private LinearLayout mAccumulatePoints = null;
    private LinearLayout mGoToSetup = null;

    private LinearLayout mPublishing = null;
    private LinearLayout mDiscussing = null;
    private LinearLayout mTransporting = null;
    private LinearLayout mCanceling = null;
    private LinearLayout mWalletLayout = null;
    private LinearLayout mOwnerFunction = null;
    private TextView mOwnerFunctionTitle = null;
    private LinearLayout mEnterPlatformAll = null;
    private LinearLayout mEmployeeManagerAll = null;
    RelativeLayout mLogInStatus = null;
    RelativeLayout mLogOutStatus = null;
    private TextView mLogIn = null;
    private TextView mLogInTelephone = null;
    private TextView mEnterStatus = null;
    private ImageView mSeeDetail = null;
    private TextView mAmountMoney = null;
    private TextView mAmountPoint = null;
    private CircleImageView mIcon = null;
    private UserInfo mUserInfo = null;
    private LinearLayout mOtherService = null;
    private LinearLayout mMyCompany = null;
    private LinearLayout mMyCar = null;
    private LinearLayout mOrderLine = null;

    private TextView mOrderAll = null;
    private LinearLayout mOrderDiscussing = null;
    private LinearLayout mOrderTransporting = null;
    private LinearLayout mOrderDone = null;
    private LinearLayout mOrderCancel = null;
    private LinearLayout mUserGuide = null;

    //
    private int mPersonalTid = -1;
    private MyHandler mHandler = null;

    private NumSign mNumSign = null;

    private HashMap<Integer, QBadgeView> mQBadgeView = null;

    public MineFragment() {
        // Required empty public constructor
    }


    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        super.initHttpComponent(MineFragment.class);
        super.initAuthCheckComponent(MineFragment.class);
        mHandler = new MyHandler(this);
        mNumSign = new NumSign();
        mQBadgeView = new HashMap<>();
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        mRootView = inflater.inflate(R.layout.fragment_mine, container, false);
        mWallet = mRootView.findViewById(R.id.text_enter_my_wallet);
        mResource = mRootView.findViewById(R.id.enter_resource);
        mResource.setOnClickListener(this);
        mWallet.setOnClickListener(this);

        mDailService = mRootView.findViewById(R.id.layout_dail_service);
        mDailService.setOnClickListener(this);

        mEnterPlatform = mRootView.findViewById(R.id.layout_enter_platform);
        mEnterPlatform.setOnClickListener(this);

        mEmployeeManager = mRootView.findViewById(R.id.layout_employee_manager);
        mEmployeeManager.setOnClickListener(this);

        mSetup = mRootView.findViewById(R.id.layout_personal_setup);
        mSetup.setOnClickListener(this);

        mEnterGroup = mRootView.findViewById(R.id.layout_enter_group);
        mEnterGroup.setOnClickListener(this);

        mFollowOfficialAccount = mRootView.findViewById(R.id.layout_follow_official_account);
        mFollowOfficialAccount.setOnClickListener(this);

        mAccumulatePoints = mRootView.findViewById(R.id.layout_accumulate_points);
        mAccumulatePoints.setOnClickListener(this);

        mGoToSetup = mRootView.findViewById(R.id.layout_goto_setup);
        mGoToSetup.setOnClickListener(this);

        mPublishing = mRootView.findViewById(R.id.layout_publishing);
        mPublishing.setOnClickListener(this);

        mDiscussing = mRootView.findViewById(R.id.layout_discussing);
        mDiscussing.setOnClickListener(this);

        mTransporting = mRootView.findViewById(R.id.layout_transporting);
        mTransporting.setOnClickListener(this);

        mCanceling = mRootView.findViewById(R.id.layout_canceling);
        mCanceling.setOnClickListener(this);

        mLogIn = mRootView.findViewById(R.id.logout_notice_login);
        mLogIn.setOnClickListener(this);

        mWalletLayout = mRootView.findViewById(R.id.layout_my_wallet);
        mOwnerFunction = mRootView.findViewById(R.id.layout_owner_function);
        mOwnerFunctionTitle = mRootView.findViewById(R.id.layout_owner_function_title);
        mEmployeeManagerAll = mRootView.findViewById(R.id.layout_employee_manager_all);
        mEnterPlatformAll = mRootView.findViewById(R.id.layout_enter_platform_all);
        mLogInStatus = mRootView.findViewById(R.id.layout_login_status);
        mLogOutStatus = mRootView.findViewById(R.id.layout_logout_status);

        mSeeDetail = mRootView.findViewById(R.id.img_see_detail);
        mSeeDetail.setOnClickListener(this);

        mAmountMoney = mRootView.findViewById(R.id.tv_amount_of_money);
        mAmountPoint = mRootView.findViewById(R.id.tv_amount_of_point);

        mIcon = mRootView.findViewById(R.id.civ_avatar);
        mLogInTelephone = mRootView.findViewById(R.id.tv_user_phone);
        mEnterStatus = mRootView.findViewById(R.id.tv_enter_status);

        mOtherService = mRootView.findViewById(R.id.layout_other_service);

        mMyCompany = mRootView.findViewById(R.id.layout_my_company);
        mMyCompany.setOnClickListener(this);
        mMyCar = mRootView.findViewById(R.id.layout_my_car);
        mMyCar.setOnClickListener(this);
        mOrderLine = mRootView.findViewById(R.id.layout_order_line);
        mOrderLine.setOnClickListener(this);

        mOrderAll = mRootView.findViewById(R.id.enter_order_info);
        mOrderAll.setOnClickListener(this);
        mOrderDiscussing = mRootView.findViewById(R.id.layout_order_discussing);
        mOrderDiscussing.setOnClickListener(this);
        mOrderTransporting = mRootView.findViewById(R.id.layout_order_transporting);
        mOrderTransporting.setOnClickListener(this);
        mOrderDone = mRootView.findViewById(R.id.layout_order_done);
        mOrderDone.setOnClickListener(this);
        mOrderCancel = mRootView.findViewById(R.id.layout_order_canceling);
        mOrderCancel.setOnClickListener(this);

        updateWalletInfo();
        updateUserInfo();
        updateAuthUI();
        refreshCompanyView();

        mUserGuide = mRootView.findViewById(R.id.layout_user_guide);
        mUserGuide.setOnClickListener(this);

        Message message = new Message();
        message.what = HANDLER_GET_NUM_SIGN;
        mHandler.sendMessageDelayed(message, 1000);

        return mRootView;
    }

    private void updateUserInfo(){
        mUserInfo = UserInfoController.Instance().getUserInfo();
        if(mUserInfo != null){
            String maskPhone = mUserInfo.getMobilephone().substring(0, 3) + "****" +
                    mUserInfo.getMobilephone().substring(7, 11);
            mLogInTelephone.setText(maskPhone);
            Glide.with(this).load(UserInfoController.Instance().getUserInfo().getHead_pic()).into(mIcon);
            if(UserInfoController.Instance().getUserInfo().getRole() == 2) {
                mEnterStatus.setVisibility(View.VISIBLE);
                mEnterStatus.setText("公司 " +
                        UserInfoController.Instance().getUserInfo().getCompany_count() +
                        " | " +
                        "车辆 " +
                        UserInfoController.Instance().getUserInfo().getTruck_count());
            }
            else if(UserInfoController.Instance().getUserInfo().getRole() == 3){
                mEnterStatus.setVisibility(View.VISIBLE);
                mEnterStatus.setText("车辆 " +
                        UserInfoController.Instance().getUserInfo().getTruck_status());
            }
            else{
                mEnterStatus.setVisibility(View.INVISIBLE);
            }
        }
    }

    private void updateAuthUI() {
        if(!AuthController.Instance().checkLogin()){
            mWalletLayout.setVisibility(View.GONE);
            mOwnerFunction.setVisibility(View.GONE);
            mOwnerFunctionTitle.setVisibility(View.GONE);
            mEmployeeManagerAll.setVisibility(View.GONE);
            mEnterPlatformAll.setVisibility(View.GONE);
            mLogInStatus.setVisibility(View.GONE);
            mLogOutStatus.setVisibility(View.VISIBLE);
            mOtherService.setVisibility(View.GONE);
        }
        else{
            mWalletLayout.setVisibility(View.VISIBLE);
            mOwnerFunction.setVisibility(View.VISIBLE);
            mOwnerFunctionTitle.setVisibility(View.VISIBLE);
            mEmployeeManagerAll.setVisibility(View.VISIBLE);
            mEnterPlatformAll.setVisibility(View.VISIBLE);
            mLogInStatus.setVisibility(View.VISIBLE);
            mLogOutStatus.setVisibility(View.GONE);
        }
    }

    @Override
    public void onClick(View v) {
        if(v.getId() == R.id.text_enter_my_wallet){
            Intent intent = new Intent(this.getActivity(), UserWalletActivity.class);
            startActivity(intent);
        }
        else if(v.getId() == R.id.enter_resource){
            Intent intent = new Intent(this.getActivity(), MyResourceManagerActivity.class);
            intent.putExtra("TabIndex", 0);
            startActivity(intent);
        }
        else if(v.getId() == R.id.layout_dail_service){
            Intent dialIntent =  new Intent(Intent.ACTION_DIAL, Uri.parse("tel:" + SERVICE_PHONE));//跳转到拨号界面，同时传递电话号码
            startActivity(dialIntent);
        }
        else if(v.getId() == R.id.layout_enter_platform){
            DialogUtils.showAlertDialog(getActivity(),
                    getResources().getString(R.string.title_choose_enter_role),
                    getResources().getString(R.string.title_choose_enter_role_meta),
                    getResources().getString(R.string.text_enter_company),
                    getResources().getString(R.string.text_enter_personal),
                    true,
                    new DialogUtils.AlertDialogBtnClickListener() {
                        @Override
                        public void clickPositive() {
                            //negative
                            Intent intent = new Intent(MineFragment.this.getActivity(), EnterPlatformCompanyStepOneActivity.class);
                            startActivity(intent);
                        }
                        @Override
                        public void clickNegative() {
                            //positive
                            Intent intent = new Intent(MineFragment.this.getActivity(), EnterPlatformPersonalStepOneActivity.class);
                            startActivity(intent);
                        }
                    });
        }
        else if(v.getId() == R.id.layout_employee_manager){
            Intent intent = new Intent(MineFragment.this.getActivity(), EmployeeManagerActivity.class);
            startActivity(intent);
        }
        else if(v.getId() == R.id.layout_personal_setup || v.getId() == R.id.layout_goto_setup){
            if(!AuthController.Instance().checkLogin()){
                Intent intent = new Intent(MineFragment.this.getActivity(), LogInActivity.class);
                startActivityForResult(intent, ACTION_LOGIN);
            }
            else {
                Intent intent = new Intent(MineFragment.this.getActivity(), SetupActivity.class);
                startActivityForResult(intent, ACTION_SETUP);
            }
        }
        else if(v.getId() == R.id.layout_enter_group){
            Intent intent = new Intent(MineFragment.this.getActivity(), EnterGroupActivity.class);
            startActivity(intent);
        }
        else if(v.getId() == R.id.layout_follow_official_account){
            Intent intent = new Intent(MineFragment.this.getActivity(), FollowOfficialAccountActivity.class);
            startActivity(intent);
        }
        else if(v.getId() == R.id.layout_accumulate_points){
            Intent intent = new Intent(MineFragment.this.getActivity(), AccumulatePointsActivity.class);
            startActivity(intent);
        }
        else if(v.getId() == R.id.layout_publishing){
            Intent intent = new Intent(MineFragment.this.getActivity(), MyResourceManagerActivity.class);
            intent.putExtra("TabIndex", 1);
            startActivity(intent);
        }
        else if(v.getId() == R.id.layout_discussing){
            Intent intent = new Intent(MineFragment.this.getActivity(), MyResourceManagerActivity.class);
            intent.putExtra("TabIndex", 2);
            startActivity(intent);
        }
        else if(v.getId() == R.id.layout_transporting){
            Intent intent = new Intent(MineFragment.this.getActivity(), MyResourceManagerActivity.class);
            intent.putExtra("TabIndex", 3);
            startActivity(intent);
        }
        else if(v.getId() == R.id.layout_canceling){
            Intent intent = new Intent(MineFragment.this.getActivity(), MyResourceManagerActivity.class);
            intent.putExtra("TabIndex", 5);
            startActivity(intent);
        }
        else if(v.getId() == R.id.logout_notice_login){
            Intent intent = new Intent(MineFragment.this.getActivity(), LogInActivity.class);
            startActivityForResult(intent, ACTION_LOGIN);
        }
        else if(v.getId() == R.id.img_see_detail){
            if(!UserActionRecord.Instance().getSeeWalletDetail()){
                UserActionRecord.Instance().setSeeWalletDetail(true);
                mSeeDetail.setImageResource(R.drawable.ic_see);
                if(mUserInfo != null) {
                    mAmountMoney.setText(mUserInfo.getIncome());
                    mAmountPoint.setText(Integer.toString(mUserInfo.getCurrent_points()));
                }
                else{
                    mAmountMoney.setText("0");
                    mAmountPoint.setText("0");
                }
            }
            else{
                UserActionRecord.Instance().setSeeWalletDetail(false);
                mSeeDetail.setImageResource(R.drawable.ic_hide);
                mAmountMoney.setText("****");
                mAmountPoint.setText("****");
            }
        }
        else if(v.getId() == R.id.layout_my_company){
            Intent intent = new Intent(mRootView.getContext(), CompanyListActivity.class);
            startActivity(intent);
        }
        else if(v.getId() == R.id.layout_my_car){
            if(UserInfoController.Instance().getUserInfo().getRole() == 2) {
                Intent intent = new Intent(mRootView.getContext(), CompanyTruckListActivity.class);
                startActivity(intent);
            }
            else if(UserInfoController.Instance().getUserInfo().getRole() == 3){
                Intent intent = new Intent(mRootView.getContext(), PersonalTruckDetailInfoActivity.class);
                intent.putExtra("tid", mPersonalTid);
                startActivity(intent);
            }
        }
        else if(v.getId() == R.id.layout_order_line){
            if(UserInfoController.Instance().getUserInfo().getRole() == 2) {
                Intent intent = new Intent(mRootView.getContext(), CompanyLineListActivity.class);
                startActivity(intent);
            }
            else if(UserInfoController.Instance().getUserInfo().getRole() == 3){
                Intent intent = new Intent(mRootView.getContext(), PersonalLineListActivity.class);
                startActivity(intent);
            }
            else{

            }
        }
        else if(v.getId() == R.id.enter_order_info){
            Intent intent = new Intent(MineFragment.this.getActivity(), MyOrderManagerActivity.class);
            intent.putExtra("TabIndex", 0);
            startActivity(intent);
        }
        else if(v.getId() == R.id.layout_order_transporting){
            Intent intent = new Intent(MineFragment.this.getActivity(), MyOrderManagerActivity.class);
            intent.putExtra("TabIndex", 2);
            startActivity(intent);
        }
        else if(v.getId() == R.id.layout_order_discussing){
            Intent intent = new Intent(MineFragment.this.getActivity(), MyOrderManagerActivity.class);
            intent.putExtra("TabIndex", 1);
            startActivity(intent);
        }
        else if(v.getId() == R.id.layout_order_done){
            Intent intent = new Intent(MineFragment.this.getActivity(), MyOrderManagerActivity.class);
            intent.putExtra("TabIndex", 3);
            startActivity(intent);
        }
        else if(v.getId() == R.id.layout_order_canceling){
            Intent intent = new Intent(MineFragment.this.getActivity(), MyOrderManagerActivity.class);
            intent.putExtra("TabIndex", 4);
            startActivity(intent);
        }
        else if(v.getId() == R.id.layout_user_guide){
            Intent intent = new Intent(getContext(), UserGuideActivity.class);
            startActivity(intent);
        }
        else{

        }
    }

    private void updateWalletInfo() {
        if(UserActionRecord.Instance().getSeeWalletDetail()){
            mSeeDetail.setImageResource(R.drawable.ic_see);
            if(mUserInfo != null) {
                mAmountMoney.setText(mUserInfo.getIncome());
                mAmountPoint.setText(Integer.toString(mUserInfo.getCurrent_points()));
            }
            else{
                mAmountMoney.setText("0");
                mAmountPoint.setText("0");
            }
        }
        else{
            mSeeDetail.setImageResource(R.drawable.ic_hide);
            mAmountMoney.setText("****");
            mAmountPoint.setText("****");
        }
    }

    @Override
    public void onResume() {
        super.onResume();
    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        //此处可以根据两个Code进行判断，本页面和结果页面跳过来的值
        if (requestCode == ACTION_LOGIN) {
            updateAuthUI();
        }
        else if(requestCode == ACTION_SETUP){
            updateAuthUI();
        }
        else {
            /**/
        }
    }

    @Override
    protected void onLogIn() {

    }

    @Override
    protected void onLogOut() {

    }

    @Override
    protected void onUserChanged() {
        updateWalletInfo();
        updateUserInfo();
        updateAuthUI();
        refreshCompanyView();
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
    }

    private void refreshCompanyView(){
        UserInfo info = UserInfoController.Instance().getUserInfo();
        if(info == null){
            mOtherService.setVisibility(View.GONE);
            mEnterPlatform.setVisibility(View.GONE);
            mEmployeeManager.setVisibility(View.GONE);
        }
        else {
            if (info.getRole() == 2) {
                mOtherService.setVisibility(View.VISIBLE);
                mMyCompany.setVisibility(View.VISIBLE);
                mEnterPlatform.setVisibility(View.GONE);
                mEmployeeManager.setVisibility(View.VISIBLE);
            } else if (info.getRole() == 3) {
                mOtherService.setVisibility(View.VISIBLE);
                mMyCompany.setVisibility(View.INVISIBLE);
                mEnterPlatform.setVisibility(View.GONE);
                mEmployeeManager.setVisibility(View.GONE);
            } else if (info.getRole() == 1) {
                mOtherService.setVisibility(View.GONE);
                mEnterPlatform.setVisibility(View.VISIBLE);
                mEmployeeManager.setVisibility(View.GONE);
            } else {
                mOtherService.setVisibility(View.GONE);
                mEnterPlatform.setVisibility(View.GONE);
                mEmployeeManager.setVisibility(View.GONE);
            }
        }
    }

    private void executeGetNumSign(){
        HashMap<String, String> header = new HashMap<String, String>();
        header.put("token", AuthController.Instance().getToken());

        sendHttpRequest(
                IHttpRequest.RequestMethod.GET_METHOD,
                RemoteAPI.REQUEST_V1_USER_NUM_SIGN,
                header,
                null,
                RemoteAPICmd.REQUEST_V1_USER_NUM_SIGN);
    }

    private void refreshNumSignView(){
        if(mNumSign != null){
            Log.d(TAG, "mNumSign != null");
            showBadgeView(R.id.iv_order_discussing, mNumSign.getOrder_num1());
            showBadgeView(R.id.iv_order_transporting, mNumSign.getOrder_num3());
            showBadgeView(R.id.iv_order_done, mNumSign.getOrder_num5());
            showBadgeView(R.id.iv_order_canceling, mNumSign.getOrder_num4());

            Log.d(TAG, "getSg_num1： " + mNumSign.getSg_num1());
            Log.d(TAG, "getSg_num5： " + mNumSign.getSg_num5());
            Log.d(TAG, "getSg_num3： " + mNumSign.getSg_num3());
            Log.d(TAG, "getSg_num6： " + mNumSign.getSg_num6());

            showBadgeView(R.id.iv_resource_publishing, mNumSign.getSg_num1());
            showBadgeView(R.id.iv_resource_discussing, mNumSign.getSg_num5());
            showBadgeView(R.id.iv_resource_transporting, mNumSign.getSg_num3());
            showBadgeView(R.id.iv_resource_canceling, mNumSign.getSg_num6());
        }
        else{
            Log.d(TAG, "mNumSign == null");
            showBadgeView(R.id.iv_order_discussing, 0);
            showBadgeView(R.id.iv_order_transporting, 0);
            showBadgeView(R.id.iv_order_done, 0);
            showBadgeView(R.id.iv_order_canceling, 0);

            showBadgeView(R.id.iv_resource_publishing, 0);
            showBadgeView(R.id.iv_resource_discussing, 0);
            showBadgeView(R.id.iv_resource_transporting, 0);
            showBadgeView(R.id.iv_resource_publishing, 0);
        }
    }

    @Override
    protected void onHttpResponse(int actionId, String response) {
        try {
            JSONObject res = new JSONObject(response);
            Gson gson = new Gson();
            if(actionId == RemoteAPICmd.REQUEST_V1_USER_NUM_SIGN){
                Log.d(TAG, "onResponse: " + response);
                ResponseInfo responseInfo = gson.fromJson(response, ResponseInfo.class);
                if(responseInfo != null && responseInfo.getStatus() == 1){
                    mNumSign = null;
                    mNumSign = gson.fromJson(res.getString("data"), NumSign.class);
                    refreshNumSignView();
                }

                Message message = new Message();
                message.what = HANDLER_GET_NUM_SIGN;
                mHandler.sendMessageDelayed(message, 1000);
            }
        }
        catch (JSONException e) {
            e.printStackTrace();
        }
    }

    @Override
    protected void onHttpErrorResponse(int actionId, String response) {
        if(actionId == RemoteAPICmd.REQUEST_V1_USER_NUM_SIGN){
            Message message = new Message();
            message.what = HANDLER_GET_NUM_SIGN;
            mHandler.sendMessageDelayed(message, 1000);
        }
    }

    private class MyHandler extends Handler {
        WeakReference<MineFragment> mFragment;

        MyHandler(MineFragment fragment) {
            mFragment = new WeakReference<MineFragment>(fragment);
        }

        @Override
        public void handleMessage(Message msg) {
            MineFragment fragment = mFragment.get();
            switch (msg.what){
                case HANDLER_GET_NUM_SIGN:
                    executeGetNumSign();
                default:
                    break;
            }
        }
    }

    /**
     * BottomNavigationView显示角标
     *
     * @param layout layout索引
     * @param showNumber 显示的数字，小于等于0是将不显示
     */
    private void showBadgeView(int layout, int showNumber) {
        if(mQBadgeView.containsKey(layout)){
            QBadgeView badgeView = mQBadgeView.get(layout);
            badgeView.setBadgeNumber(showNumber);
        }
        else {
            // 显示badegeview
            QBadgeView badgeView = new QBadgeView(mRootView.getContext());
            badgeView.bindTarget(mRootView.findViewById(layout));
            badgeView.setBadgeGravity(Gravity.END | Gravity.TOP);
            badgeView.setBadgeBackgroundColor(Color.parseColor("#FF0000"));
            badgeView.setBadgeTextColor(Color.WHITE);
            badgeView.setBadgeTextSize(8, true);
            badgeView.setGravityOffset(-3, -3, true);
            badgeView.setShowShadow(false);
            badgeView.setBadgeNumber(showNumber);
            mQBadgeView.put(layout, badgeView);
        }
    }
}